﻿using System;

namespace Function4
{
    /// <summary>
    ///用do-while循环语句来计算PI=4*(1-1/3+1/5+...+1/n)，要求当1/n<0.000001时停止计算。
    /// </summary>
    class Program
    {
        static void Main(string[] args)
        {
            int a = 1;
            int i = 1;
            double sum = 0.0;
            do
            {
                sum = sum + 1.0 / (2 * i - 1) * a;
                a = -a;
                i = i + 1;


            } while (i<500000.5);

            Console.WriteLine("PI=" + sum * 4.0);
        }
    }
}
